package com.tao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tao.pojo.Product;
import com.tao.pojo.vo.ProductVo;
import com.tao.pojo.vo.ResponseResult;
import com.tao.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/client/product")
public class ClientProductController {

    @Autowired
    private ProductService productService;
   /*获取地址列表 成功 */
    @PostMapping("/list")
    public Object list(@RequestBody ProductVo product){
        HashMap<String, Object> map = new HashMap<>();
        Page<Product> page = new Page<>(product.getCurrent(),product.getSize());
        LambdaQueryWrapper<Product> lqw = new LambdaQueryWrapper<>();
        lqw.eq(!ObjectUtils.isEmpty(product.getAddressName()),Product::getAddressName,product.getAddressName());
        lqw.eq(!ObjectUtils.isEmpty(product.getCategoryName()), Product::getCategoryName,product.getCategoryName());
        Page<Product> list = productService.page(page, lqw);
        map.put("list",list.getRecords());
        map.put("total",list.getTotal());
        return ResponseResult.success(map);
    }
}
